<template>
  <el-card class="box-card" shadow="never">
    <div slot="header" class="clearfix">
      <h3>基本资料</h3>
    </div>
    <el-form ref="formLabelAlign"  label-width="80px" :model="formLabelAlign" :rules="rules">
      <el-form-item label="登录名称">
        <el-input v-model="formLabelAlign.username" disabled></el-input>
      </el-form-item>
      <el-form-item label="用户昵称"  prop="nickname">
        <el-input v-model="formLabelAlign.nickname"></el-input>
      </el-form-item>
      <el-form-item label="用户邮箱"  prop="email">
        <el-input v-model="formLabelAlign.email"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="update">提交修改</el-button>
        <el-button @click="reset">重置</el-button>
      </el-form-item>
    </el-form>

  </el-card>

</template>

<script>
import { getuser, putuserinfo } from '@/api/user'
import { mapMutations } from 'vuex'
export default {
  name: 'BigEventIndex',

  data () {
    return {
      formLabelAlign: {
        username: '',
        nickname: '',
        email: ''
      },
      rules: {
        nickname: [{ required: true, message: '请输入用户昵称', trigger: 'blur' },
          { min: 1, max: 10, message: '长度为1-10位', trigger: 'blur' }],
        email: [
          { required: true, message: '请输入邮箱地址', trigger: 'blur' },
          { type: 'email', message: '请输入正确的邮箱地址', trigger: 'blur' }]

      }
    }
  },
  created () {
    this.getuser()
  },

  mounted () {

  },

  methods: {
    ...mapMutations(['setUserInfo']),

    async getuser () {
      const { data: res } = await getuser()
      this.formLabelAlign = res.data
    },
    async update () {
      await this.$refs.formLabelAlign.validate()
      const { data } = await putuserinfo(this.formLabelAlign)
      this.setUserInfo(this.formLabelAlign)
      this.$message.success(data.message)
    },
    reset () {
      this.$refs.formLabelAlign.resetFields()
    }
  }
}
</script>

<style lang="less" scoped>
.el-input {
  width: 25rem;
}

</style>
